from pyspark import SparkConf, SparkContext

import os

# 创建SparkConf
conf = SparkConf().setMaster('local[*]').setAppName('test_spark_app')

sc = SparkContext(conf=conf)

rdd = sc.parallelize([1, 2, 3, 4, 5])

rdd_list: list = rdd.collect()
print(rdd_list)

num = rdd.reduce(lambda a, b: a + b)
print(num)

num_list: list = rdd.take(3)
print(num_list)

# 停止spark
sc.stop()
